package com.zlll.winner.mapper.media;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zlll.winner.business.model.media.MediaNewList;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zlll.winner.business.vo.media.MediaNewListVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 电台节目列表 Mapper 接口
 * </p>
 *
 * @author Walert
 * @since 2019-10-04
 */
public interface MediaNewListMapper extends BaseMapper<MediaNewList> {

//    List<Map<String, Object>> fetchNewListPage(Integer pageNo, Integer pageSize, IPage<Map<String, Object>> page);

    @Select("select " +
            " t.id as menuId, " +
            " m2.head_img as hostOneHeadImg," +
            " m3.head_img as hostTwoHeadImg," +
            " t.`name` as menuName, " +
            " t.begin_time as menuBeginTime, " +
            " t.end_time as menuEndTime, " +
            " #{showDate} as showDate, " +
            " m1.*  " +
            "from media_menu t " +
            "left join media_new_list m1 on (m1.menu_id = t.id and m1.is_del = 0 and m1.show_date = #{showDate} ) " +
            "left join media_host m2 on (m1.host_one_id = m2.id and m2.is_del = 0) " +
            "left join media_host m3 on (m1.host_two_id = m3.id and m3.is_del = 0) " +
            "${ew.customSqlSegment} " +
            "order by t.id asc")
    IPage<MediaNewListVo> fetchNewListPage(IPage<MediaNewListVo> page, @Param("ew") Wrapper<MediaNewListVo> queryWrapper, @Param("showDate")Long showDate);


    @Select("select " +
            " t.id as menuId, " +
            " m2.head_img as hostOneHeadImg," +
            " m3.head_img as hostTwoHeadImg," +
            " t.`name` as menuName, " +
            " t.begin_time as menuBeginTime, " +
            " t.end_time as menuEndTime, " +
            " #{showDate} as showDate, " +
            " m1.*  " +
            "from media_menu t " +
            "left join media_new_list m1 on (m1.menu_id = t.id and m1.is_del = 0 and m1.show_date = #{showDate} ) " +
            "left join media_host m2 on (m1.host_one_id = m2.id and m2.is_del = 0) " +
            "left join media_host m3 on (m1.host_two_id = m3.id and m3.is_del = 0) " +
            "${ew.customSqlSegment} " +
            "order by t.id asc")
    List<MediaNewListVo> fetchNewListList(@Param("ew") Wrapper<MediaNewListVo> queryWrapper, @Param("showDate")Long showDate);



    @Select("select " +
            " m2.head_img as hostOneHeadImg," +
            " m3.head_img as hostTwoHeadImg," +
            " t.* " +
            "from media_new_list t " +
            "left join media_menu m1 on (t.menu_id = m1.id and m1.is_del = 0) " +
            "left join media_host m2 on (t.host_one_id = m2.id and m2.is_del = 0) " +
            "left join media_host m3 on (t.host_two_id = m3.id and m3.is_del = 0) " +
            "where " +
            "t.show_begin_time <= #{currTime} and t.show_end_time >= #{currTime} and t.is_del = 0 and m1.type=1" )
    MediaNewListVo getMediaNewListByTime(@Param("currTime")Long currTime);

}
